package com.heisen.fileapi.service.fallback;

import com.heisen.base.entity.Api;
import com.heisen.base.exception.RRException;
import com.heisen.fileapi.dto.FileDto;
import com.heisen.fileapi.service.FileService;
import feign.Response;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;
import java.util.List;

/**
 * @author sen
 * @description
 * @date 2023/12/18 17:32
 */
@Slf4j
@Component
public class FileServiceFallback implements FallbackFactory<FileService> {

    @Override
    public FileService create(Throwable throwable) {
        return new FileService() {
            @Override
            public Api<List<Serializable>> uploadFile(MultipartFile[] files, FileDto fileDto) {
                return  Api.fail("feign上传失败");
            }

            @Override
            public Api<String> fileUrl(String fileId) {
                return  Api.fail("feign获取文件url失败");
            }

            @Override
            public Api<String> delete(String fileId) {
                return  Api.fail("feign删除文件url失败");
            }

            @Override
            public Response download(String fileId, HttpServletResponse response) {
                throw new RRException("feign下载文件url失败");
            }
        };
    }
}
